package com.elvis.chat.utils.add;

import org.jivesoftware.smack.packet.PacketExtension;

public class AttachmentExtension implements PacketExtension {
    private AttachmentInfo attachment;
    public static String ELEMENT_NAME = "attachment-message";
    public static String NAMESPACE = "http://www.pekall.com/protocol/attachment-message";

    public AttachmentExtension(AttachmentInfo attachment) {
	this.attachment = attachment;
    }

    public AttachmentExtension(String message) {
	if (AttachmentInfo.checkIsMedia(message)) {
	    AttachmentManager manager = new AttachmentManager();
	    attachment = manager.loadAttachment(message);
	}
    }

    public String getElementName() {
	return ELEMENT_NAME;
    }

    public String getNamespace() {
	return NAMESPACE;
    }

    public String toXML() {
	StringBuffer buf = new StringBuffer();
	if (attachment != null)
	    buf.append(attachment.toString());
	return buf.toString();
    }
}